<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
<style type="text/css">
.form{
    width: 300px;
    height: 300px;
    background-color: #00ccFF;
    margin: 0 auto;
    padding: 50px;
    text-align: right;
}
.w-150{
    width: 200px;
    margin-bottom: 10px;
}

.h-30{
    height: 30px;
}

.button {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 10px;
    width: 230px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin-top: 10px;
}
.margin-bottom-10{
    margin-bottom:10px;
}

</style>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
    </script>
</head>
<body>

    <div class="form">
        <div>
            邮箱:  <input type="email" class="w-150 h-30" id="email">
        </div>
        <div>
            密码:  <input type="password" class="w-150 h-30" id="p1"/>
        </div>
        <div>
            确认密码:  <input type="password" class="w-150 h-30" id="p2"/>
        </div>
        <div>
            验证码:  <input type="password" class="w-150 h-30" id="code"/>
        </div>

        <div class="margin-top-10">
            <a id="codeGet">获取验证码</a>
        </div>


        <div>
            <button class="button" id="register">注册</button>
        </div>

    </div>


</body>
<script>
$(document).ready(function(){
  $("#register").click(function(){
    var email = $("#email").val();
    var p1 = $("#p1").val();
    var p2 = $("#p2").val();
    var code = $("#code").val();

     if(!email){
       alert("请输入邮箱");
       return;
    }

    if(!code){
        alert("请输入验证码");
        return;
    }

    if(p1 == p2){

    }else{
        alert("两次密码输入不一致");
    }
    $.ajax(
        {
            url:"/api/user/register/"+encodeURI(email)+"/"+p1+"/"+code,
            type: "POST",
            success:function(result){
			    alert("注册成功")
                window.location.href = "login.html";
			},
			error:function(err){
			    alert(err.responseText);
			}
	    });

  });

  $("#codeGet").click(function(){
      var email = $("#email").val();
      var p1 = $("#p1").val();
      var p2 = $("#p2").val();
      if(!p1){
          alert("请输入密码");
          return;
      }
      if(!p2){
          alert("请确认密码");
          return;
      }
      if(p1 != p2){
          alert("两次密码输入不一致");
      }
     if(!email){
       alert("请输入邮箱");
       return;
    }
      /*var time = localStorage.getItem("retime");
      var t = new Date().getTime()/1000;
      if(time !==undefined && t-time<60){
          alert("短信验证码60秒只能点击一次。\n在"+Math.ceil(60-(t-time))+"秒之后可以再次点击。");
          return;
      }
      localStorage.setItem("retime",new Date().getTime()/1000);*/
      $.ajax({
            url:"/api/code/create/"+email,
            type: "GET",
            success:function(result){
			    $("#codeGet").text("已发送");
			},
			error:function(err){
			    alert(err.responseText);
			}
	    });


  });

});
</script>
</html>